import pygame
import datetime
import sys
import os
import os
# 设置显示环境变量
os.environ['DISPLAY'] = ':0'
os.environ['XAUTHORITY'] = '/home/w-dingyu01@uos/.Xauthority'

# 初始化pygame
pygame.init()

# 获取屏幕信息，避免遮挡任务栏
info = pygame.display.Info()
screen_width = info.current_w
screen_height = info.current_h

# 保存原始屏幕尺寸
WINDOWED_SIZE = (800, 600)
original_screen_width = screen_width
original_screen_height = screen_height

# 设置全屏但不遮挡任务栏
screen = pygame.display.set_mode((original_screen_width, original_screen_height), pygame.NOFRAME)
pygame.display.set_caption("")
is_fullscreen = True  # 设置初始全屏状态为True

# 定义颜色
"""
颜色常量定义模块
定义了程序中使用的各种颜色RGB值
"""
# 黑色，RGB值为(0, 0, 0)
BLACK = (0, 0, 0)
# 白色，RGB值为(255, 255, 255)
WHITE = (255, 255, 255)
# 蓝色，RGB值为(0, 120, 255)
BLUE = (0, 120, 255)
# 深灰色，RGB值为(50, 50, 50)
GRAY = (50, 50, 50)
# 浅蓝色，RGB值为(173, 216, 230)
LIGHT_BLUE = (173, 216, 230)
# 浅绿色，RGB值为(144, 238, 144)
LIGHT_GREEN = (144, 238, 144)
# 橙色，RGB值为(255, 165, 0)
ORANGE = (255, 165, 0)
# 浅灰色，RGB值为(211, 211, 211)
LIGHT_GRAY = (211, 211, 211)

# 路径设置
path = '/home/w-dingyu01@uos/dy外网/My_model/pygame测试/'

# 字体设置
try:
    clock_font = pygame.font.Font(os.path.join(path, 'clock.ttf'), 150)
    date_font = pygame.font.Font(os.path.join(path, '像素.ttf'), 60)
    reminder_font = pygame.font.Font(os.path.join(path, 'Ubuntu_18.04_SimHei.ttf'), 36)
    step_font = pygame.font.Font(os.path.join(path, 'Ubuntu_18.04_SimHei.ttf'), 28)
except:
    # 如果自定义字体加载失败，使用系统默认字体
    clock_font = pygame.font.Font(None, 150)
    date_font = pygame.font.Font(None, 60)
    reminder_font = pygame.font.Font(None, 36)
    step_font = pygame.font.Font(None, 28)

# 下班提醒信息
reminder_title = "下班提醒"
reminder_text = "请记得登记工时和打卡！"
reminder_steps = [
    "1. 打开工时系统",
    "2. 登记今日工作内容", 
    "3. 确认提交",
    "4. 打卡下班"
]

# 游戏主循环
running = True
clock = pygame.time.Clock()
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

while running:
    # 处理事件
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:  # 按ESC键退出
                running = False
            elif event.key == pygame.K_f:  # 按F键切换全屏
                is_fullscreen = not is_fullscreen
                if is_fullscreen:
                    # 切换到全屏模式
                    screen = pygame.display.set_mode((original_screen_width, original_screen_height), pygame.NOFRAME)
                else:
                    # 返回窗口模式
                    screen = pygame.display.set_mode(WINDOWED_SIZE, pygame.RESIZABLE)
        elif event.type == pygame.VIDEORESIZE:  # 窗口大小调整事件
            # 只有在窗口模式下才响应尺寸调整
            if not is_fullscreen:
                WINDOWED_SIZE = event.size
                screen = pygame.display.set_mode(WINDOWED_SIZE, pygame.RESIZABLE)
    
    # 获取当前屏幕尺寸
    current_screen_width, current_screen_height = screen.get_size()
    
    # 根据屏幕尺寸动态调整字体大小
    clock_font_size = int(current_screen_height * 0.15)
    date_font_size = int(current_screen_height * 0.05)
    
    # 重新创建字体对象
    try:
        clock_font = pygame.font.Font(os.path.join(path, 'clock.ttf'), clock_font_size)
        date_font = pygame.font.Font(os.path.join(path, '像素.ttf'), date_font_size)
    except:
        clock_font = pygame.font.Font(None, clock_font_size)
        date_font = pygame.font.Font(None, date_font_size)

    # 填充背景色 - 使用深蓝色背景
    screen.fill((30, 30, 60))
    
    # 获取当前时间
    current_time = datetime.datetime.now()
    
    # 格式化时间显示
    time_str = current_time.strftime("%H:%M:%S")
    date_str = current_time.strftime("%Y-%m-%d %A")
    
    # 渲染时间文本
    time_text = clock_font.render(time_str, True, WHITE)
    date_text = date_font.render(date_str, True, LIGHT_BLUE)
    
    # 添加文本阴影效果
    time_shadow = clock_font.render(time_str, True, GRAY)
    date_shadow = date_font.render(date_str, True, GRAY)
    
    # 获取文本的矩形区域以便居中显示
    time_rect = time_text.get_rect(center=(current_screen_width/2, current_screen_height/4))
    date_rect = date_text.get_rect(center=(current_screen_width/2, current_screen_height/4 + current_screen_height*0.12))
    
    # 绘制阴影（偏移几个像素）
    screen.blit(time_shadow, (time_rect.x + 3, time_rect.y + 3))
    screen.blit(date_shadow, (date_rect.x + 2, date_rect.y + 2))
    
    # 绘制文本
    screen.blit(time_text, time_rect)
    screen.blit(date_text, date_rect)
    
    # 绘制下班提醒信息
    title_text = reminder_font.render(reminder_title, True, WHITE)
    title_rect = title_text.get_rect(center=(current_screen_width/2, current_screen_height/2 + current_screen_height*0.1))
    screen.blit(title_text, title_rect)
    
    reminder_main = reminder_font.render(reminder_text, True, ORANGE)
    reminder_rect = reminder_main.get_rect(center=(current_screen_width/2, current_screen_height/2 + current_screen_height*0.15))
    screen.blit(reminder_main, reminder_rect)
    
    # 绘制步骤
    start_y = current_screen_height/2 + current_screen_height*0.2
    for i, step in enumerate(reminder_steps):
# 使用step_font字体渲染步骤文本，颜色为LIGHT_GREEN
        step_text = step_font.render(step, True, LIGHT_GREEN)
# 获取渲染文本的矩形区域，并将其中心点设置在屏幕中央垂直方向的位置
        step_rect = step_text.get_rect(center=(current_screen_width/2, start_y + i * 40))
# 将渲染好的文本绘制到屏幕的指定位置
        screen.blit(step_text, step_rect)
    
    # 显示当前时间戳
    timestamp_text = step_font.render(f"最后提醒: {timestamp}", True, LIGHT_GRAY)
    timestamp_rect = timestamp_text.get_rect(bottomright=(current_screen_width - 20, current_screen_height - 20))
    screen.blit(timestamp_text, timestamp_rect)
    
    # 在窗口模式下显示提示文字
    if not is_fullscreen:
        try:
            help_font = pygame.font.Font(os.path.join(path, 'Ubuntu_18.04_SimHei.ttf'), 20)
        except:
            help_font = pygame.font.Font(None, 20)
            
        help_text = help_font.render("按 F 切换全屏，ESC 退出，可拖动调整窗口大小", True, (150, 150, 150))
        help_rect = help_text.get_rect(center=(current_screen_width/2, current_screen_height - 20))
        screen.blit(help_text, help_rect)
    
    # 更新显示
    pygame.display.flip()
    
    # 控制帧率，每秒更新10次就足够了
    clock.tick(10)

# 退出pygame
pygame.quit()
sys.exit()